package com.wsj.web.action.admin.file;

import java.io.File;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.wsj.util.tool.FileUplaodAndManageForStorage;
import com.wsj.web.form.admin.ImgActionFrom;

public class ImagesUploadAction extends Action{
	
	private FileUplaodAndManageForStorage imgUpload;

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		// TODO Auto-generated method stub
		ImgActionFrom imgpath = (ImgActionFrom)form;
		String uploadPath="fileUpload"+File.separator+imgpath.getDesc()+File.separator;
		imgUpload.setMyFiles(imgpath.getPath());
		imgUpload.setPath(uploadPath);
		String fileName = imgUpload.uploadFile(request, String.valueOf(System.currentTimeMillis()));
		String imgPath = uploadPath + fileName;
		System.out.print("-------------------------------后台上传了新图片" + imgPath);
		request.getSession().setAttribute("pathSelected", imgpath.getDesc());
		return mapping.findForward("success");
	}

	public FileUplaodAndManageForStorage getImgUpload() {
		return imgUpload;
	}

	public void setImgUpload(FileUplaodAndManageForStorage imgUpload) {
		this.imgUpload = imgUpload;
	}
	
	

}
